<?php
namespace app\admin\controller;
use app\admin\controller\Base;
use app\admin\model\RoleModel as M;
use think\Session;

class Role extends Base{
    //权限列表显示
    public function index(){
        $this->isLogin();
        $m = new M();
        $roles = $m->getRoleList();
        $this->assign('roles',$roles);
        return $this->fetch('role_management');
    }
    //分配权限管理
    public function roleAdd(){
        $this->isLogin();
        return $this->fetch('role_management_add');
    }
    //编辑
    public function edit(){
        $this->isLogin();
        return $this->fetch('role_management_edit');
    }
    //权限查看
    public function roleDetail(){
        $this->isLogin();
        return $this->fetch('role_management_look');
    }
    //分配权限
    public function rolePermission(){
        $this->isLogin();
        $m = new M();
        //个人用户拥有的相应权限
        $role = $m->getRolePermission();
        $auth['rules'] = explode(',',$role['rules']);
        $this->assign('auth',$auth);
        $this->assign('role',$role);
        //所有功能模块(无限极分类)
        $roles = $m->rolePermission ();
        $this->assign('roles',$roles);
        return $this->fetch('role_management_permissions');
    }
    //修改权限
    public function roleUpdate(){
        $this->isLogin();
        $ids = input('ids');
        $m = new M();
        $res = $m->roleUpdate($ids);
        return $res;
    }
}